home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Info / For Developers / PlayerPRO 5.2 Dev.Kit Mac / MADH Library 5.2 / MADLibrary Source / DelayOutPut.c < prev    next >
Encoding:
Text File  |  1999-01-11  |  32.8 KB  |  1,065 lines  |  [TEXT/CWIE]

  1. /********************                        ***********************/
  2. //
  3. //    Player PRO 5.0 - DRIVER SOURCE CODE -
  4. //
  5. //    Library Version 5.0
  6. //
  7. //    To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
  8. //
  9. //    Antoine ROSSET
  10. //    16 Tranchees
  11. //    1206 GENEVA
  12. //    SWITZERLAND
  13. //
  14. //    COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
  15. //
  16. //    Thank you for your interest in PlayerPRO !
  17. //
  18. //    FAX:                (+41 22) 346 11 97
  19. //    PHONE:             (+41 79) 203 74 62
  20. //    Internet:     RossetAntoine@bluewin.ch
  21. //
  22. /********************                        ***********************/
  23.  
  24. #include "RDriver.h"
  25. #include "RDriverInt.h"
  26.  
  27. void MADCreateOverShoot( MADDriverRec *intDriver)
  28. {
  29.     long    i, x;
  30.     
  31.     switch( intDriver->DriverSettings.outPutBits)
  32.     {
  33.         case 16:
  34.             intDriver->DASCBuffer = (long*) MADNewPtrClear( ( (long) intDriver->ASCBUFFER * 8L) + intDriver->MDelay*2L*8L, intDriver->lib);
  35.         break;
  36.         
  37.         case 8:
  38.             intDriver->DASCBuffer8 = (short*) MADNewPtrClear( ( (long) intDriver->ASCBUFFER * 4L) + intDriver->MDelay*2L*4L, intDriver->lib);
  39.             
  40.             intDriver->OverShoot = (Ptr) MADNewPtrClear( 256L * 32L, intDriver->lib);
  41.     
  42.             for( i = 0; i < 256L * 16L; i++)                        intDriver->OverShoot[ i] = 0;
  43.             for( i = 256L * 16L, x = 0; i < 256L * 17L; i++, x++)    intDriver->OverShoot[ i] = x;
  44.             for( i = 256L * 17L; i < 256L * 32L; i++)                intDriver->OverShoot[ i] = 0xFF;
  45.             
  46.             
  47.             intDriver->OverShoot += 256L*16L;
  48.             intDriver->OverShoot += 128L;
  49.         break;
  50.     }
  51. }
  52.  
  53. void MADKillOverShoot( MADDriverRec *intDriver)
  54. {
  55.     switch( intDriver->DriverSettings.outPutBits)
  56.     {
  57.         case 16:
  58.             if( intDriver->DASCBuffer != 0L) DisposePtr( (Ptr) intDriver->DASCBuffer);
  59.             intDriver->DASCBuffer = 0L;
  60.         break;
  61.  
  62.         case 8:
  63.             if( intDriver->OverShoot != 0L)
  64.             {
  65.                 intDriver->OverShoot -= 128L;
  66.                 intDriver->OverShoot -= 256L*16L;
  67.                 DisposePtr( (Ptr) intDriver->OverShoot);
  68.                 intDriver->OverShoot = 0L;
  69.             }
  70.             
  71.             if( intDriver->DASCBuffer8 != 0L) DisposePtr( (Ptr) intDriver->DASCBuffer8);
  72.             intDriver->DASCBuffer8 = 0L;
  73.         break;
  74.     }
  75. }
  76.  
  77. void Sampler16AddDelay( Channel *curVoice, long    *ASCBuffer, MADDriverRec *intDriver)
  78. {
  79.     long                chnVol, chnVol2;
  80.     long                i = intDriver->ASCBUFFER;
  81.     char                tByte = 0;
  82.     long                *ASCBuffer1, *ASCBuffer2;
  83.     Boolean            killSample = false;
  84.     
  85.     ///
  86.     long                aDD, aCC = curVoice->lAC, off;
  87.     
  88.     #if defined(powerc) || defined (__powerc)
  89.     {
  90.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  91.     aDD = temp * (1 << BYTEDIV);
  92.     }
  93.     #else
  94.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  95.     #endif
  96.  
  97.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  98.     ///
  99.     
  100.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  101.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  102.     
  103.     if( (curVoice->ID % 2) == 0)
  104.     {
  105.         ASCBuffer1 = ASCBuffer;
  106.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  107.     }
  108.     else
  109.     {
  110.         ASCBuffer2 = ASCBuffer +1L;
  111.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  112.     }
  113.     
  114.     //*****************************************
  115.     if( intDriver->DriverSettings.TickRemover) MADTickRemoverStart8( curVoice, ASCBuffer1, ASCBuffer2, intDriver);
  116.     //*****************************************
  117.     
  118.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  119.     
  120.     {
  121.         Ptr        SndBuffer = curVoice->curPtr;
  122.         long    RightWeight, LeftWeight, preOff = curVoice->preOff;
  123.       char  preVal = curVoice->preVal, preVal2 = curVoice->preVal2;
  124.         
  125.         while( i-- > 0)
  126.         {
  127.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) (aCC>>BYTEDIV);
  128.             
  129.             if( preOff != off)
  130.             {
  131.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  132.                 {
  133.                     preOff = off;
  134.                     if( (SndBuffer + off +1 >= curVoice->maxPtr && !curVoice->pingpong) ||
  135.                             (SndBuffer + off +1 <= curVoice->begPtr + curVoice->loopBeg && curVoice->pingpong))
  136.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) (aCC>>BYTEDIV);}
  137.                     preVal = *(SndBuffer + off);
  138.                 }
  139.                 else
  140.                 {
  141.                     preVal = preVal2;
  142.                     preOff = off;
  143.                     
  144.                     if( SndBuffer + off + 1 >= curVoice->maxPtr)
  145.                     {
  146.                         if( curVoice->loopSize > 0) 
  147.                         {
  148.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  149.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) (aCC>>BYTEDIV);
  150.                           preOff = off;
  151.                           
  152.                           SndBuffer = curVoice->begPtr + curVoice->loopBeg;
  153.                           SndBuffer--;
  154.                         }
  155.                         else    // If TICK remove
  156.                         {
  157.                             MADTickLoopFill8( curVoice, ASCBuffer1, ASCBuffer2, i, (tByte * chnVol), (tByte * chnVol2));
  158.                             killSample = true;
  159.                             break;
  160.                         }
  161.                     }
  162.                     preVal2 = *(SndBuffer + off + 1);
  163.                 }
  164.             }
  165.             
  166.             tByte = (    LeftWeight *     preVal  + RightWeight *     *(SndBuffer + off + 1)) >> BYTEDIV;            aCC += aDD;
  167.             
  168.             *ASCBuffer1 += (tByte * chnVol);                ASCBuffer1 += 2;
  169.             *ASCBuffer2 += (tByte * chnVol2);                ASCBuffer2 += 2;
  170.         }
  171.         
  172.         if( killSample)
  173.         {
  174.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  175.         }
  176.         else
  177.         {
  178.             if( (aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  179.             else curVoice->preOff = 0xFFFFFFFF;    //(long) (aCC>>BYTEDIV);
  180.             curVoice->preVal = preVal;
  181.             curVoice->preVal2 = *(SndBuffer + off + 1);
  182.             curVoice->curPtr = SndBuffer + (aCC>>BYTEDIV);
  183.         }
  184.         
  185.         curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  186.         
  187.         curVoice->lastWordL = (tByte * chnVol);
  188.         curVoice->lastWordR = (tByte * chnVol2);
  189.     }
  190. }
  191.  
  192. void Sampler16AddDelayStereo( Channel *curVoice, long    *ASCBuffer, MADDriverRec *intDriver)
  193. {
  194.     long                chnVol, chnVol2;
  195.     long                i = intDriver->ASCBUFFER;
  196.     char                tByteL = 0, tByteR = 0;
  197.     long                *ASCBuffer1, *ASCBuffer2;
  198.     Boolean            killSample = false;
  199.     
  200.     ///
  201.     long                aDD, aCC = curVoice->lAC, off;
  202.     
  203.     #if defined(powerc) || defined (__powerc)
  204.     {
  205.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  206.     aDD = temp * ( 1 << BYTEDIV);
  207.     }
  208.     #else
  209.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  210.     #endif
  211.     
  212.     
  213.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  214.     ///
  215.     
  216.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  217.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  218.     
  219.     if( (curVoice->ID % 2) == 0)
  220.     {
  221.         ASCBuffer1 = ASCBuffer;
  222.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  223.     }
  224.     else
  225.     {
  226.         ASCBuffer2 = ASCBuffer +1L;
  227.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  228.     }
  229.     
  230.     //*****************************************
  231.     if( intDriver->DriverSettings.TickRemover) MADTickRemoverStart8( curVoice, ASCBuffer1, ASCBuffer2, intDriver);
  232.     //*****************************************
  233.     
  234.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  235.     
  236.     {
  237.         Ptr        SndBuffer = curVoice->curPtr;
  238.         long    RightWeight, LeftWeight, preOff = curVoice->preOff;
  239.       char    preVal = curVoice->preVal, preValR = curVoice->preValR, preVal2 = curVoice->preVal2, preVal2R = curVoice->preVal2R;
  240.         
  241.         while( i-- > 0)
  242.         {
  243.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) 2*(aCC>>BYTEDIV);
  244.             
  245.             if( preOff != off)
  246.             {
  247.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  248.                 {
  249.                     preOff = off;
  250.                     if( (SndBuffer + off +3 >= curVoice->maxPtr && !curVoice->pingpong) ||
  251.                             (SndBuffer + off +2 <= curVoice->begPtr + curVoice->loopBeg && curVoice->pingpong))
  252.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) 2*(aCC>>BYTEDIV);}
  253.                     preVal = *(SndBuffer + off);
  254.                     preValR = *(SndBuffer + off + 1);
  255.                 }
  256.                 else
  257.                 {
  258.                     preVal = preVal2;
  259.                     preValR = preVal2R;
  260.                     preOff = off;
  261.                     
  262.                     if( SndBuffer + off + 3 >= curVoice->maxPtr)
  263.                     {
  264.                         if( curVoice->loopSize > 0) 
  265.                         {
  266.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  267.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) 2*(aCC>>BYTEDIV);
  268.                           preOff = off;
  269.                           
  270.                           SndBuffer = curVoice->begPtr + curVoice->loopBeg;
  271.                           SndBuffer-=2;
  272.                         }
  273.                         else    // If TICK remove
  274.                         {
  275.                             MADTickLoopFill8( curVoice, ASCBuffer1, ASCBuffer2, i, (tByteL * chnVol), (tByteR * chnVol2));
  276.                             killSample = true;
  277.                             break;
  278.                         }
  279.                     }
  280.                     preVal2 = *(SndBuffer + off + 2);
  281.                     preVal2R = *(SndBuffer + off + 3);
  282.                 }
  283.             }
  284.             
  285.             tByteL = (    LeftWeight *     preVal + RightWeight *     *(SndBuffer + off + 2)) >> BYTEDIV;            *ASCBuffer1 += (tByteL * chnVol);        ASCBuffer1 += 2;
  286.             tByteR = (    LeftWeight *     preValR + RightWeight *     *(SndBuffer + off + 3)) >> BYTEDIV;        *ASCBuffer2 += (tByteR * chnVol2);    ASCBuffer2 += 2;
  287.             
  288.             aCC += aDD;
  289.         }
  290.         if( killSample)
  291.         {
  292.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  293.         }
  294.         else
  295.         {
  296.             if( 2*(aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  297.             else curVoice->preOff = 0xFFFFFFFF;
  298.             curVoice->preVal = preVal;
  299.             curVoice->preValR = preValR;
  300.             curVoice->preVal2 = *(SndBuffer + off + 2);
  301.             curVoice->preVal2R = *(SndBuffer + off + 3);
  302.             curVoice->curPtr = SndBuffer + 2*(aCC>>BYTEDIV);
  303.         }
  304.         
  305.         curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  306.         
  307.         curVoice->lastWordL = (tByteL * chnVol);
  308.         curVoice->lastWordR = (tByteR * chnVol2);
  309.     }
  310. }
  311.  
  312.  
  313. void Sampler16Addin16Delay( Channel *curVoice, long    *ASCBuffer, MADDriverRec *intDriver)
  314. {
  315.     long                i = intDriver->ASCBUFFER;
  316.     long                chnVol, chnVol2;
  317.     long                off, tShort = 0;
  318.     long                *ASCBuffer1, *ASCBuffer2;
  319.     Boolean            killSample = false;
  320.     ///
  321.     long                aDD, aCC = curVoice->lAC;
  322.     
  323.     #if defined(powerc) || defined (__powerc)
  324.     {
  325.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  326.     aDD = temp * ( 1 << BYTEDIV);
  327.     }
  328.     #else
  329.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  330.     #endif
  331.  
  332.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  333.     ///
  334.     
  335.     chnVol2        = DoVolPanning256( 0, curVoice, intDriver);
  336.     chnVol         = DoVolPanning256( 1, curVoice, intDriver);
  337.     
  338.     if( (curVoice->ID % 2) == 0)
  339.     {
  340.         ASCBuffer1 = ASCBuffer;
  341.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  342.     }
  343.     else
  344.     {
  345.         ASCBuffer2 = ASCBuffer +1L;
  346.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  347.     }
  348.     
  349.     //*****************************************
  350.     if( intDriver->DriverSettings.TickRemover) MADTickRemoverStart8( curVoice, ASCBuffer1, ASCBuffer2, intDriver);
  351.     //*****************************************
  352.     
  353.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  354.  
  355.     {
  356.         short        *SndBuffer = (short*)    curVoice->curPtr;
  357.         long        RightWeight, LeftWeight, preOff = curVoice->preOff;
  358.         short     spreVal = curVoice->spreVal, spreVal2 = curVoice->spreVal2;;
  359.         
  360.         while( i-- > 0)
  361.         {
  362.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;    off = (aCC>>BYTEDIV);
  363.             
  364.             if( preOff != off)
  365.             {
  366.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  367.                 {
  368.                     preOff = off;
  369.                     if( (SndBuffer + off +1 >= (short*) curVoice->maxPtr && !curVoice->pingpong) ||
  370.                             (SndBuffer + off +1 <= (short*) (curVoice->begPtr + curVoice->loopBeg) && curVoice->pingpong))
  371.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) (aCC>>BYTEDIV);}
  372.                     spreVal = *(SndBuffer + off);
  373.                 }
  374.                 else
  375.                 {
  376.                     spreVal = spreVal2;
  377.                     preOff = off;
  378.                     
  379.                     if( SndBuffer + off + 1 >= (short*) curVoice->maxPtr)
  380.                     {
  381.                         if( curVoice->loopSize > 0) 
  382.                         {
  383.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  384.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;
  385.                           off = (long) (aCC>>BYTEDIV);
  386.                           preOff = off;
  387.                           
  388.                           SndBuffer = (short*) (curVoice->begPtr + curVoice->loopBeg);
  389.                           SndBuffer--;
  390.                         }
  391.                         else    // If TICK remove
  392.                         {
  393.                             MADTickLoopFill8( curVoice, ASCBuffer1, ASCBuffer2, i, (tShort * chnVol) >> 8, (tShort * chnVol2) >> 8);
  394.                             killSample = true;
  395.                             break;
  396.                         }
  397.                     }
  398.                     spreVal2 = *(SndBuffer + off + 1);
  399.                 }
  400.             }
  401.             
  402.             tShort = (    LeftWeight *     spreVal + RightWeight *     *(SndBuffer + off + 1)) >> BYTEDIV;            aCC += aDD;
  403.             
  404.             *ASCBuffer1 += (tShort * chnVol) >> 8;        ASCBuffer1 += 2;
  405.             *ASCBuffer2 += (tShort * chnVol2) >> 8;        ASCBuffer2 += 2;
  406.         }
  407.         
  408.         if( killSample)
  409.         {
  410.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  411.         }
  412.         else
  413.         {
  414.             if( (aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  415.             else curVoice->preOff = 0xFFFFFFFF;    
  416.             curVoice->spreVal = spreVal;
  417.             curVoice->spreVal2 = *(SndBuffer + off + 1);
  418.             curVoice->curPtr = (Ptr) (SndBuffer + (aCC>>BYTEDIV));
  419.         }
  420.         
  421.         curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  422.         
  423.         curVoice->lastWordL = (tShort * chnVol) >> 8;
  424.         curVoice->lastWordR = (tShort * chnVol2) >> 8;
  425.     }
  426. }
  427.  
  428. void Sampler16Addin16DelayStereo( Channel *curVoice, long    *ASCBuffer, MADDriverRec *intDriver)
  429. {
  430.     long                i = intDriver->ASCBUFFER;
  431.     long                chnVol, chnVol2;
  432.     long                off, tShortL = 0, tShortR = 0;
  433.     long                *ASCBuffer1, *ASCBuffer2;
  434.     Boolean            killSample = false;
  435.     ///
  436.     long                aDD, aCC = curVoice->lAC;
  437.     
  438.     #if defined(powerc) || defined (__powerc)
  439.     {
  440.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  441.     aDD = temp * ( 1 << BYTEDIV);
  442.     }
  443.     #else
  444.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  445.     #endif
  446.     
  447.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  448.     ///
  449.     
  450.     chnVol2        = DoVolPanning256( 0, curVoice, intDriver);
  451.     chnVol         = DoVolPanning256( 1, curVoice, intDriver);
  452.     
  453.     if( (curVoice->ID % 2) == 0)
  454.     {
  455.         ASCBuffer1 = ASCBuffer;
  456.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  457.     }
  458.     else
  459.     {
  460.         ASCBuffer2 = ASCBuffer +1L;
  461.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  462.     }
  463.     
  464.     //*****************************************
  465.     if( intDriver->DriverSettings.TickRemover) MADTickRemoverStart8( curVoice, ASCBuffer1, ASCBuffer2, intDriver);
  466.     //*****************************************
  467.  
  468.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  469.     
  470.     {
  471.         short    *SndBuffer = (short*)    curVoice->curPtr;
  472.         long    RightWeight, LeftWeight, preOff = curVoice->preOff;
  473.       short    spreVal = curVoice->spreVal, spreValR = curVoice->spreValR, spreVal2 = curVoice->spreVal2, spreVal2R = curVoice->spreVal2R;
  474.         
  475.         while( i-- > 0)
  476.         {
  477.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = 2*(aCC>>BYTEDIV);
  478.             
  479.             if( preOff != off)
  480.             {
  481.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  482.                 {
  483.                     preOff = off;
  484.                     if( (SndBuffer + off +3 >= (short*) curVoice->maxPtr && !curVoice->pingpong) ||
  485.                             (SndBuffer + off +2 <= (short*) (curVoice->begPtr + curVoice->loopBeg) && curVoice->pingpong))
  486.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) 2*(aCC>>BYTEDIV);}
  487.                     spreVal = *(SndBuffer + off);
  488.                     spreValR = *(SndBuffer + off + 1);
  489.                 }
  490.                 else
  491.                 {
  492.                     spreVal = spreVal2;
  493.                     spreValR = spreVal2R;
  494.                     preOff = off;
  495.                     
  496.                     if( SndBuffer + off + 3 >= (short*) curVoice->maxPtr)
  497.                     {
  498.                         if( curVoice->loopSize > 0) 
  499.                         {
  500.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  501.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) 2*(aCC>>BYTEDIV);
  502.                           preOff = off;
  503.                           
  504.                           SndBuffer = (short*) (curVoice->begPtr + curVoice->loopBeg);
  505.                           SndBuffer-=2;
  506.                         }
  507.                         else    // If TICK remove
  508.                         {
  509.                             MADTickLoopFill8( curVoice, ASCBuffer1, ASCBuffer2, i, (tShortL * chnVol) >> 8, (tShortR * chnVol2) >> 8);
  510.                             killSample = true;
  511.                             break;
  512.                         }
  513.                     }
  514.                     spreVal2 = *(SndBuffer + off + 2);
  515.                     spreVal2R = *(SndBuffer + off + 3);
  516.                 }
  517.             }
  518.             
  519.             tShortL = (    LeftWeight *     spreVal + RightWeight *     *(SndBuffer + off + 2)) >> BYTEDIV;        *ASCBuffer1 += (tShortL * chnVol) >> 8;        ASCBuffer1 += 2;
  520.             tShortR = (    LeftWeight *     spreValR + RightWeight *     *(SndBuffer + off + 3)) >> BYTEDIV;        *ASCBuffer2 += (tShortR * chnVol2) >> 8;        ASCBuffer2 += 2;
  521.             
  522.             aCC += aDD;
  523.         }
  524.         
  525.         if( killSample)
  526.         {
  527.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  528.         }
  529.         else
  530.         {
  531.             if( 2*(aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  532.             else curVoice->preOff = 0xFFFFFFFF;
  533.             curVoice->spreVal = spreVal;
  534.             curVoice->spreValR = spreValR;
  535.             curVoice->spreVal2 = *(SndBuffer + off + 2);
  536.             curVoice->spreVal2R = *(SndBuffer + off + 3);
  537.             curVoice->curPtr = (Ptr) (SndBuffer + 2*(aCC>>BYTEDIV));
  538.         }
  539.         
  540.         curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  541.         
  542.         aCC -= aDD;
  543.         curVoice->lastWordL = (tShortL * chnVol) >> 8;
  544.         curVoice->lastWordR = (tShortR * chnVol2) >> 8;
  545.     }
  546. }
  547.  
  548. void Sample16BufferAddDelay( Channel *curVoice, register long    *ASCBuffer, MADDriverRec *intDriver)
  549. {
  550.     if( curVoice->amp == 16)
  551.     {
  552.         if( curVoice->stereo) Sampler16Addin16DelayStereo( curVoice, ASCBuffer, intDriver);
  553.         else Sampler16Addin16Delay( curVoice, ASCBuffer, intDriver);
  554.     }
  555.     else if( curVoice->amp == 8)
  556.     {
  557.         if( curVoice->stereo) Sampler16AddDelayStereo( curVoice, ASCBuffer, intDriver);
  558.         else Sampler16AddDelay( curVoice, ASCBuffer, intDriver);
  559.     }
  560. }
  561.  
  562. void Play16StereoDelay( MADDriverRec *intDriver)
  563. {
  564. short        *ASCBuffer, valP = 0x7FFFL, valN = -0x7FFFL;
  565. long        *ttt, i;
  566.  
  567.     for( i = 0 ; i < intDriver->DriverSettings.numChn; i++) Sample16BufferAddDelay( &intDriver->chan[ i], intDriver->DASCBuffer, intDriver);
  568.     
  569.     ttt = intDriver->DASCBuffer;
  570.     ASCBuffer = (short*) intDriver->IntDataPtr;
  571.     
  572.     i = intDriver->ASCBUFFER*2;
  573.     
  574.     while( i-- > 0)
  575.     {
  576.         if( *ttt > valP) *ASCBuffer++ = valP;
  577.         else if( *ttt < valN) *ASCBuffer++ = valN;
  578.         else *ASCBuffer++ = *ttt;
  579.         
  580.         *ttt++ = 0;
  581.     }
  582. }
  583.  
  584. void Sampler8in8AddDelay( Channel *curVoice, short    *ASCBuffer, MADDriverRec *intDriver)
  585. {
  586.     char            tByte;
  587.     long             i = intDriver->ASCBUFFER;
  588.     long            chnVol, chnVol2, off;
  589.     short            *ASCBuffer1, *ASCBuffer2;
  590.     Boolean        killSample = false;
  591.     
  592.     ///
  593.     long                    aDD, aCC = curVoice->lAC;
  594.     
  595.     #if defined(powerc) || defined (__powerc)
  596.     {
  597.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  598.     aDD = temp * ( 1 << BYTEDIV);
  599.     }
  600.     #else
  601.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  602.     #endif
  603.     
  604.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  605.     ///
  606.     
  607.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  608.     
  609.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  610.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  611.     
  612.     if( (curVoice->ID % 2) == 0)
  613.     {
  614.         ASCBuffer1 = ASCBuffer;
  615.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  616.     }
  617.     else
  618.     {
  619.         ASCBuffer2 = ASCBuffer +1L;
  620.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  621.     }
  622.     
  623.     {
  624.         Ptr            SndBuffer = curVoice->curPtr;
  625.         long        RightWeight, LeftWeight, preOff = curVoice->preOff;
  626.       char      preVal = curVoice->preVal, preVal2 = curVoice->preVal2;
  627.         
  628.         while( i-- > 0)
  629.         {
  630.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = aCC>>BYTEDIV;
  631.             
  632.             if( preOff != off)
  633.             {
  634.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  635.                 {
  636.                     preOff = off;
  637.                     if( (SndBuffer + off +1 >= curVoice->maxPtr && !curVoice->pingpong) ||
  638.                             (SndBuffer + off +1 <= curVoice->begPtr + curVoice->loopBeg && curVoice->pingpong))
  639.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) (aCC>>BYTEDIV);}
  640.                     preVal = *(SndBuffer + off);
  641.                 }
  642.                 else
  643.                 {
  644.                     preVal = preVal2;
  645.                     preOff = off;
  646.                     
  647.                     if( SndBuffer + off + 1 >= curVoice->maxPtr)
  648.                     {
  649.                         if( curVoice->loopSize > 0) 
  650.                         {
  651.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  652.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;
  653.                           off = (long) (aCC>>BYTEDIV);
  654.                           preOff = off;
  655.                           
  656.                           SndBuffer = curVoice->begPtr + curVoice->loopBeg;
  657.                           SndBuffer--;
  658.                         }
  659.                         else    // If TICK remove
  660.                         {
  661.                             killSample = true;
  662.                             break;
  663.                         }
  664.                     }
  665.                     preVal2 = *(SndBuffer + off + 1);
  666.                 }
  667.             }
  668.             
  669.             tByte = (    LeftWeight * preVal + RightWeight * *(SndBuffer + off + 1)) >> BYTEDIV;            aCC += aDD;
  670.             
  671.             *ASCBuffer1 += (chnVol * tByte) >> 8;        ASCBuffer1 += 2;
  672.             *ASCBuffer2 += (chnVol2 * tByte) >> 8;        ASCBuffer2 += 2;
  673.         }
  674.         
  675.         
  676.         if( killSample)
  677.         {
  678.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  679.         }
  680.         else
  681.         {
  682.             if( (aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  683.             else curVoice->preOff = 0xFFFFFFFF;    //(long) (aCC>>BYTEDIV);
  684.             curVoice->preVal = preVal;
  685.             curVoice->preVal2 = *(SndBuffer + off + 1);
  686.             curVoice->curPtr = SndBuffer + (aCC>>BYTEDIV);
  687.         }
  688.     }
  689.     
  690.     curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  691. }
  692.  
  693. void Sampler8in16AddDelay( Channel *curVoice, short    *ASCBuffer, MADDriverRec *intDriver)
  694. {
  695.     char                tByte;
  696.     long                chnVol, chnVol2;
  697.     long                i = intDriver->ASCBUFFER, off;
  698.     short                *ASCBuffer1, *ASCBuffer2;
  699.     Boolean            killSample = false;
  700.     
  701.     ///
  702.     long                aDD, aCC = curVoice->lAC;
  703.     
  704.     #if defined(powerc) || defined (__powerc)
  705.     {
  706.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  707.     aDD = temp * ( 1 << BYTEDIV);
  708.     }
  709.     #else
  710.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  711.     #endif
  712.     
  713.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  714.     ///
  715.     
  716.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  717.     
  718.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  719.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  720.     
  721.     if( (curVoice->ID % 2) == 0)
  722.     {
  723.         ASCBuffer1 = ASCBuffer;
  724.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  725.     }
  726.     else
  727.     {
  728.         ASCBuffer2 = ASCBuffer +1L;
  729.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  730.     }
  731.     
  732.     {
  733.         Ptr            SndBuffer = curVoice->curPtr;
  734.         long        RightWeight, LeftWeight, preOff = curVoice->preOff;
  735.         char        preVal = curVoice->preVal, preVal2 = curVoice->preVal2;
  736.         
  737.         #ifdef _INTEL_H
  738.         SndBuffer++;
  739.         #endif
  740.         
  741.         while( i-- > 0)
  742.         {
  743.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = aCC>>BYTEDIV;
  744.             
  745.             if( preOff != off)
  746.             {
  747.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  748.                 {
  749.                     preOff = off;
  750.                     if( (SndBuffer + 2*off +2 >= curVoice->maxPtr && !curVoice->pingpong) ||
  751.                             (SndBuffer + 2*off +2 <= (curVoice->begPtr + curVoice->loopBeg) && curVoice->pingpong))
  752.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) (aCC>>BYTEDIV);}
  753.                     preVal = *(SndBuffer + 2*off);
  754.                 }
  755.                 else
  756.                 {
  757.                     preVal = preVal2;
  758.                     preOff = off;
  759.                     
  760.                     if( SndBuffer + 2*off +2 >= curVoice->maxPtr)
  761.                     {
  762.                         if( curVoice->loopSize > 0) 
  763.                         {
  764.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  765.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;
  766.                           off = (long) (aCC>>BYTEDIV);
  767.                           preOff = off;
  768.                           
  769.                           SndBuffer = (curVoice->begPtr + curVoice->loopBeg);
  770.                           SndBuffer -= 2;
  771.                         }
  772.                         else    // If TICK remove
  773.                         {
  774.                             killSample = true;
  775.                             break;
  776.                         }
  777.                     }
  778.                     preVal2 = *(SndBuffer + 2*off + 2);
  779.                 }
  780.             }
  781.             
  782.             tByte = (    LeftWeight * preVal + RightWeight *     *(SndBuffer + 2*off + 2)) >> BYTEDIV;            aCC += aDD;
  783.             
  784.             *ASCBuffer1 += (chnVol * tByte) >> 8;        ASCBuffer1 += 2;
  785.             *ASCBuffer2 += (chnVol2 * tByte) >> 8;        ASCBuffer2 += 2;
  786.         }
  787.         
  788.         if( killSample)
  789.         {
  790.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  791.         }
  792.         else
  793.         {
  794.             if( (aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  795.             else curVoice->preOff = 0xFFFFFFFF;    
  796.             curVoice->preVal = preVal;
  797.             curVoice->preVal2 = *(SndBuffer + 2*off + 2);
  798.             curVoice->curPtr = (Ptr) (SndBuffer + 2*(aCC>>BYTEDIV));
  799.         }
  800.     }
  801.     
  802.     curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  803. }
  804.  
  805. void Sampler8in8AddDelayStereo( Channel *curVoice, short    *ASCBuffer, MADDriverRec *intDriver)
  806. {
  807.     char            tByteL, tByteR;
  808.     long             i = intDriver->ASCBUFFER;
  809.     long            chnVol, chnVol2;
  810.     long            off;
  811.     short            *ASCBuffer1, *ASCBuffer2;
  812.     Boolean        killSample = false;
  813.     
  814.     ///
  815.     long                aDD, aCC = curVoice->lAC;
  816.     
  817.     #if defined(powerc) || defined (__powerc)
  818.     {
  819.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  820.     aDD = temp * ( 1 << BYTEDIV);
  821.     }
  822.     #else
  823.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  824.     #endif
  825.     
  826.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  827.     ///
  828.     
  829.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  830.     
  831.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  832.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  833.     
  834.     if( (curVoice->ID % 2) == 0)
  835.     {
  836.         ASCBuffer1 = ASCBuffer;
  837.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  838.     }
  839.     else
  840.     {
  841.         ASCBuffer2 = ASCBuffer +1L;
  842.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  843.     }
  844.     
  845.     {
  846.         Ptr        SndBuffer = curVoice->curPtr;
  847.         long    RightWeight, LeftWeight, preOff = curVoice->preOff;
  848.       char    preVal = curVoice->preVal, preValR = curVoice->preValR, preVal2 = curVoice->preVal2, preVal2R = curVoice->preVal2R;
  849.         
  850.         while( i-- > 0)
  851.         {
  852.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = 2*(aCC>>BYTEDIV);
  853.             
  854.             if( preOff != off)
  855.             {
  856.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  857.                 {
  858.                     preOff = off;
  859.                     if( (SndBuffer + off +3 >= curVoice->maxPtr && !curVoice->pingpong) ||
  860.                             (SndBuffer + off +2 <= curVoice->begPtr + curVoice->loopBeg && curVoice->pingpong))
  861.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) 2*(aCC>>BYTEDIV);}
  862.                     preVal = *(SndBuffer + off);
  863.                     preValR = *(SndBuffer + off + 1);
  864.                 }
  865.                 else
  866.                 {
  867.                     preVal = preVal2;
  868.                     preValR = preVal2R;
  869.                     preOff = off;
  870.                     
  871.                     if( SndBuffer + off + 3 >= curVoice->maxPtr)
  872.                     {
  873.                         if( curVoice->loopSize > 0) 
  874.                         {
  875.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  876.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) 2*(aCC>>BYTEDIV);
  877.                           preOff = off;
  878.                           
  879.                           SndBuffer = curVoice->begPtr + curVoice->loopBeg;
  880.                           SndBuffer-=2;
  881.                         }
  882.                         else    // If TICK remove
  883.                         {
  884.                             killSample = true;
  885.                             break;
  886.                         }
  887.                     }
  888.                     preVal2 = *(SndBuffer + off + 2);
  889.                     preVal2R = *(SndBuffer + off + 3);
  890.                 }
  891.             }
  892.             
  893.             tByteL = ( LeftWeight *     preVal + RightWeight *     *(SndBuffer + off + 2)) >> BYTEDIV;        *ASCBuffer1 += (chnVol * tByteL) >> 8;        ASCBuffer1 += 2;
  894.             tByteR = ( LeftWeight *     preValR + RightWeight *     *(SndBuffer + off + 3)) >> BYTEDIV;        *ASCBuffer2 += (chnVol2 * tByteR) >> 8;        ASCBuffer2 += 2;
  895.             
  896.             aCC += aDD;
  897.         }
  898.         
  899.         if( killSample)
  900.         {
  901.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  902.         }
  903.         else
  904.         {
  905.             if( 2*(aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  906.             else curVoice->preOff = 0xFFFFFFFF;
  907.             curVoice->preVal = preVal;
  908.             curVoice->preValR = preValR;
  909.             curVoice->preVal2 = *(SndBuffer + off + 2);
  910.             curVoice->preVal2R = *(SndBuffer + off + 3);
  911.             curVoice->curPtr = SndBuffer + 2*(aCC>>BYTEDIV);
  912.         }
  913.     }
  914.     
  915.     curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  916. }
  917.  
  918. void Sampler8in16AddDelayStereo( Channel *curVoice, short    *ASCBuffer, MADDriverRec *intDriver)
  919. {
  920.     char                tByteL = 0, tByteR = 0;
  921.     long                chnVol, chnVol2;
  922.     long                i = intDriver->ASCBUFFER;
  923.     long                off;
  924.     short                *ASCBuffer1, *ASCBuffer2;
  925.     Boolean            killSample = false;
  926.     
  927.     ///
  928.     long                aDD, aCC = curVoice->lAC;
  929.     
  930.     #if defined(powerc) || defined (__powerc)
  931.     {
  932.     long double        temp = ((long double)AMIGA_CLOCKFREQ2) / (long double) ( (long double) curVoice->period * (long double) (intDriver->DriverSettings.outPutRate>>16) * (long double) intDriver->DriverSettings.oversampling);
  933.     aDD = temp * ( 1 << BYTEDIV);
  934.     }
  935.     #else
  936.     aDD = (AMIGA_CLOCKFREQ2 << BYTEDIV) / (curVoice->period * (intDriver->DriverSettings.outPutRate>>16) * intDriver->DriverSettings.oversampling);
  937.     #endif
  938.     
  939.     if( curVoice->pingpong == true && curVoice->loopType == ePingPongLoop) aDD = -aDD;    // PINGPONG
  940.     ///
  941.     
  942.     if( curVoice->curPtr >= curVoice->maxPtr && curVoice->loopSize == 0) return;
  943.     
  944.     chnVol2    = DoVolPanning256( 0, curVoice, intDriver);
  945.     chnVol    = DoVolPanning256( 1, curVoice, intDriver);
  946.     
  947.     if( (curVoice->ID % 2) == 0)
  948.     {
  949.         ASCBuffer1 = ASCBuffer;
  950.         ASCBuffer2 = ASCBuffer +1L + intDriver->MDelay*2L;
  951.     }
  952.     else
  953.     {
  954.         ASCBuffer2 = ASCBuffer +1L;
  955.         ASCBuffer1 = ASCBuffer + intDriver->MDelay*2L;
  956.     }
  957.     
  958.     {
  959.         Ptr        SndBuffer = curVoice->curPtr;
  960.         long    RightWeight, LeftWeight, preOff = curVoice->preOff;
  961.         char    preVal = curVoice->preVal, preValR = curVoice->preValR, preVal2 = curVoice->preVal2, preVal2R = curVoice->preVal2R;
  962.         
  963.         #ifdef _INTEL_H
  964.         SndBuffer++;
  965.         #endif
  966.         
  967.         while( i-- > 0)
  968.         {
  969.             RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = 2*(aCC>>BYTEDIV);
  970.             
  971.             if( preOff != off)
  972.             {
  973.                 if( curVoice->loopType == ePingPongLoop && curVoice->loopSize > 0)        // PINGPONG
  974.                 {
  975.                     preOff = off;
  976.                     if( (SndBuffer + 2*off +6 >= curVoice->maxPtr && !curVoice->pingpong) ||
  977.                             (SndBuffer + 2*off +4 <= curVoice->begPtr + curVoice->loopBeg && curVoice->pingpong))
  978.                     {curVoice->pingpong = !curVoice->pingpong; aDD = -aDD; aCC += aDD; RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight; off = (long) 2*(aCC>>BYTEDIV);}
  979.                     preVal = *(SndBuffer + 2*off);
  980.                     preValR = *(SndBuffer + 2*off + 2);
  981.                 }
  982.                 else
  983.                 {
  984.                     preVal = preVal2;
  985.                     preValR = preVal2R;
  986.                     preOff = off;
  987.                     
  988.                     if( SndBuffer + 2*off + 6 >= curVoice->maxPtr)
  989.                     {
  990.                         if( curVoice->loopSize > 0) 
  991.                         {
  992.                           aCC = aCC & ((1 << BYTEDIV) - 1);    
  993.                           RightWeight = aCC & ((1 << BYTEDIV) - 1);        LeftWeight = (1 << BYTEDIV) - RightWeight;        off = (long) 2*(aCC>>BYTEDIV);
  994.                           preOff = off;
  995.                           
  996.                           SndBuffer = curVoice->begPtr + curVoice->loopBeg;
  997.                           SndBuffer-=4;
  998.                         }
  999.                         else    // If TICK remove
  1000.                         {
  1001.                             killSample = true;
  1002.                             break;
  1003.                         }
  1004.                     }
  1005.                     preVal2 = *(SndBuffer + 2*off + 4);
  1006.                     preVal2R = *(SndBuffer + 2*off + 6);
  1007.                 }
  1008.             }
  1009.             
  1010.             tByteL = (    LeftWeight * preVal + RightWeight *     *(SndBuffer + 2*off + 4)) >> BYTEDIV;    *ASCBuffer1 += (chnVol * tByteL) >> 8;        ASCBuffer1 += 2;
  1011.             tByteR = (    LeftWeight * preValR + RightWeight *     *(SndBuffer + 2*off + 6)) >> BYTEDIV;    *ASCBuffer2 += (chnVol2 * tByteR) >> 8;        ASCBuffer2 += 2;
  1012.             aCC += aDD;
  1013.         }
  1014.         
  1015.         if( killSample)
  1016.         {
  1017.             curVoice->samplePtr    = 0L;    curVoice->curPtr    = curVoice->maxPtr;
  1018.         }
  1019.         else
  1020.         {
  1021.             if( 2*(aCC>>BYTEDIV) == preOff) curVoice->preOff = 0;
  1022.             else curVoice->preOff = 0xFFFFFFFF;
  1023.             curVoice->preVal = preVal;
  1024.             curVoice->preValR = preValR;
  1025.             curVoice->preVal2 = *(SndBuffer + 2*off + 4);
  1026.             curVoice->preVal2R = *(SndBuffer + 2*off + 6);
  1027.             curVoice->curPtr = SndBuffer + 4*(aCC>>BYTEDIV);
  1028.         }
  1029.     }
  1030.         
  1031.     curVoice->lAC = aCC & ((1 << BYTEDIV) - 1);
  1032. }
  1033.  
  1034. void Sample8BufferAddDelay( Channel *curVoice, register short *ASCBuffer, MADDriverRec *intDriver)
  1035. {
  1036.     if( curVoice->stereo)
  1037.     {
  1038.         if( curVoice->amp == 16) Sampler8in16AddDelayStereo( curVoice, ASCBuffer, intDriver);
  1039.         else Sampler8in8AddDelayStereo( curVoice, ASCBuffer, intDriver);
  1040.     }
  1041.     else
  1042.     {
  1043.         if( curVoice->amp == 16) Sampler8in16AddDelay( curVoice, ASCBuffer, intDriver);
  1044.         else Sampler8in8AddDelay( curVoice, ASCBuffer, intDriver);
  1045.     }
  1046. }
  1047.  
  1048. void Play8StereoDelay( MADDriverRec *intDriver)
  1049. {
  1050. long            i;
  1051. short            *ttt;
  1052. Ptr                ASCBuffer;
  1053.  
  1054.     for( i = 0 ; i < intDriver->DriverSettings.numChn; i++) Sample8BufferAddDelay    ( &intDriver->chan[i], intDriver->DASCBuffer8, intDriver);
  1055.  
  1056.     ttt = intDriver->DASCBuffer8;
  1057.     ASCBuffer = intDriver->IntDataPtr;
  1058.  
  1059.     i = intDriver->ASCBUFFER*2;
  1060.     while( i-- > 0)
  1061.     {
  1062.         *ASCBuffer++ = *(intDriver->OverShoot + *ttt);
  1063.         *ttt++ = 0;
  1064.     }
  1065. }